﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace HtmlHelper
{
    public class XhtmlAttribute
    {
        private string f_attributeName = "";
        public string AttributeName
        {
            get 
            { 
                return f_attributeName; 
            }
            private set
            {
                this.f_attributeName = value.ToLower().Trim();
                this.IsDirty = true;
            }
        }

        private string f_attributeValue = "";
        public string AttributeValue
        {
            get { return this.f_attributeValue; }
            set
            {
                string s = XhtmlRegex.NormalizeAttributeValue(value);
                if (this.f_attributeValue != s)
                {
                    this.f_attributeValue = s;
                    this.IsDirty = true;
                }
            }
        }


        private bool f_isDirty = true;
        internal bool IsDirty
        {
            set
            {
                f_isDirty = value;
                if (value && this.f_tag != null)
                {
                    this.f_tag.Attributes.IsDirty = true;
                }
            }
        }
        
        private string f_html = "";
        public string Html
        {
            get
            {
                if (this.f_isDirty)
                {
                    this.f_html = this.f_attributeName + "=\"" + this.f_attributeValue + "\"";
                }
                return this.f_html;
            }
        }

        public XhtmlAttribute(string html)
        {
            this.AttributeName = XhtmlRegex.getAttributeName(html);
            this.AttributeValue = XhtmlRegex.getAttributeValue(html);
        }
        public XhtmlAttribute(string attributeName, string attributeValue)
        {
            this.AttributeName = attributeName;
            this.AttributeValue = attributeValue;
        }

        private XhtmlElement f_tag = null;
        //public XhtmlElement Tag
        //{
        //    get { return f_tag; }
        //    set
        //    {
        //        this.f_tag = value;
        //        this.f_tag.Attributes.Add(this);
        //    }
        //}

    }
}

